package com.streetlight.lampcursor.ui.schedule

import android.os.Bundle
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import androidx.fragment.app.Fragment
import androidx.fragment.app.viewModels
import com.lampcursor.streetlight.databinding.FragmentScheduleBinding

class ScheduleFragment : Fragment() {

    private var _binding: FragmentScheduleBinding? = null
    private val binding get() = _binding!!
    
    private val viewModel: ScheduleViewModel by viewModels()

    override fun onCreateView(
        inflater: LayoutInflater,
        container: ViewGroup?,
        savedInstanceState: Bundle?
    ): View {
        _binding = FragmentScheduleBinding.inflate(inflater, container, false)
        return binding.root
    }

    override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
        super.onViewCreated(view, savedInstanceState)
        
        setupViews()
        setupObservers()
        setupClickListeners()
        
        // 初始加载数据
        viewModel.loadSchedules()
    }

    private fun setupViews() {
        // 初始化视图状态
    }

    private fun setupObservers() {
        viewModel.schedules.observe(viewLifecycleOwner) { schedules ->
            // 更新定时列表
        }
    }

    private fun setupClickListeners() {
        binding.btnAddSchedule.setOnClickListener {
            // 添加新定时
            viewModel.addNewSchedule()
        }
    }

    override fun onDestroyView() {
        super.onDestroyView()
        _binding = null
    }
} 